﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.Metadata.Entity;

namespace T.FAS.Runtime.Metadata.Entity.DataModel
{
    [Serializable]
    public class EntityObjectRefSchemaEntity : IRefSchemaEntity
    {
        public string ID { get; set; }
        public string Code { get; set; }
        public string Name { get; set; }
        public Dictionary<string, Attr> Attrs { get; set; }

        [Serializable]
        public class Attr
        {
            public string Code { get; set; }
            public string Text { get; set; }
            public string DataType { get; set; }
            public int Length { get; set; }
            public int Precision { get; set; }
            public bool IsNullable { get; set; }
            public bool IsList { get; set; }
            public string DefaultValue { get; set; }
            public string RelatedEntityObjectID { get; set; }

            public static Attr Mapping(EntityObject eo, EntityObjectAttribute attr)
            {
                if (eo == null || attr == null) return default;
                var column = new Attr
                {
                    Code = attr.Code,
                    Text = attr.Name,
                    DataType = attr.DataType,
                    Length = attr.Length,
                    Precision = attr.Precision,
                    IsNullable = attr.IsNullable,
                    IsList = attr.IsList,
                    DefaultValue = attr.DefaultValue,
                    RelatedEntityObjectID = attr.RelatedEntityObjectID,
                };
                return column;
            }
        }
    }
}
